<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  @active_tab = 'people'
  add_crumb t('People'), context_url(@context, :context_users_url)

  translated_title = @context.is_a?(Course) ? t('Course Roster') : t('Group Roster')
  content_for :page_title, join_title(translated_title, @context.name)

  css_bundle :roster

  is_teacher = can_do(@context, @current_user, :manage_students)
%>

<div class="ic-Action-header">
  <div class="ic-Action-header__Primary">
    <h1 class="screenreader-only">{{#t}}People{{/t}}</h1>
  </div>
  <div class="ic-Action-header__Secondary">
    {{> views/context/roster_right_side}}
  </div>
</div>
<% if @context.is_a?(Course) %>
  <% js_bundle :roster %>
  <% js_env :canManageCourse => can_do(@context, @current_user, :manage) %>
<% else %>
  <div class="roster-container">
    <div class="roster roster-column student_roster">
      <h2><%= @primary_users.keys.first %></h2>
      <ul class="user-list">
      <% @primary_users[@primary_users.keys.first].each do |student| %>
        <li class="user-list__item" id="user_<%= student.id %>">
          <%= avatar(student, context_code: @context.asset_string, size: 30) %>
          <div class="user-list__item-details">
            <a href="<%= context_url(@context, :context_user_url, student.id) %>" class="user_name"><%= is_teacher ? student.name : student.short_name %></a>
            <% if is_teacher %>
              <div class="short_name"><%= student.short_name %></div>
              <div class="email"><%= student.email %></div>
              <% if @enrollments_hash %>
                <% @enrollments_hash[student.id].each do |e| %>
                  <div class="course_section"><%= e.try(:course_section).try(:display_name) %></div>
                <% end %>
              <% end %>
            <% end %>
          </div>
        </li>
      <% end %>
      </ul>
    </div>
    <% unless !@secondary_users || @secondary_users.empty? %>
    <div class="roster roster-column teacher_roster">
      <h2><%= @secondary_users.keys.first %></h2>
      <ul class="user-list">
      <% @secondary_users[@secondary_users.keys.first].each do |teacher| %>
        <li class="user-list__item" id="user_<%= teacher.id %>">
          <%= avatar(teacher, context_code: @context.context.asset_string, size: 30) %>
          <div class="user-list__item-details">
            <a href="<%= context_url(@context.context, :context_user_url, teacher.id) %>" class="user_name"><%= teacher.name %></a>
            <% if is_teacher %>
              <div class="short_name"><%= teacher.short_name %></div>
              <div class="email"><%= teacher.email %></div>
              <% if @enrollments_hash %>
                <% @enrollments_hash[teacher.id].each do |e| %>
                  <div class="course_section"><%= e.try(:course_section).try(:display_name) %></div>
                <% end %>
              <% end %>
            <% end %>
          </div>
        </li>
      <% end %>
      </ul>
    </div>
    <% end %>
  </div>
<% end %>
